package cn.initcap.common;

import lombok.Data;

/**
 * @author initcap
 * @date Created in 2018/8/8 PM1:08.
 */
@Data
public class Result<T> {

    private int code;

    private String msg;

    private T data;

    private Result() {
        this.code = 0;
        this.msg = "SUCCESS";
    }

    private Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Result(T data) {
        this.code = 0;
        this.msg = "SUCCESS";
        this.data = data;
    }

    public static Result success() {
        return new Result();
    }

    public static Result success(Object data) {
        return new Result<>(data);
    }

    public static Result fail(ErrorCode errorCode) {
        return new Result<>(errorCode.getCode(), errorCode.getMsg());
    }
}
